<?php
require_once ($INCLUDE_PATH . "./include/WebService2Db.php");
class IndexModel {
    public function selectuser($username,$password) {
        $DB=new DB_MYSQL;
        $sql="SELECT *  FROM `hh_user` WHERE `account` = '".$username."' AND `password` = '".$password."'";
        $query = $DB->query_first($sql,DB);
        return $query;
    }
    public function updatauser($username,$password,$userInfo) {
        $now=date("Y-m-d H:i:s",time());
        $key = md5($username.$now);
        $ip=DyAuth::getip();
        $DB=new DB_MYSQL;
        $DB->connect();
        $sql="update `".PRE."_user` set `last_login`= '".$now."',`last_ip`='".$ip."' WHERE `account` = '".$username."' AND `password` = '".$password."';";
        $DB->update($sql, DB);
        $res[1] = $DB->affected_rows;

        $sql ="insert into `".PRE."_login_info`(id,user_id,login_time,l_key,ip)" .
            "VALUES(NULL,'".$userInfo['uid']."','".$now."','".$key."','".$ip."');";
          $DB->insert($sql, DB);
        $res[2]  =$DB->affected_rows;
        $res[3]  = $key;
        setcookie("adminname",$username);
        setcookie("adminpassword",$password);
        setcookie("usertype",$userInfo['user_type']);
        setcookie("adminlogintime",time());
        return  $res;
    }
    public function getServerInfo() {
        $server = array();
        $server["ip"]= $_SERVER["REMOTE_ADDR"];
        $server["host_url"]= $_SERVER['HTTP_HOST'];
        $server["os"]=$_ENV['OS'];
        $server["SERVER_SOFTWARE"]=$_SERVER["SERVER_SOFTWARE"];
        $phpv = @phpversion();
        $server["phpv"]=$phpv;
        $server["webpath"]=APP_ROOT;
        $server["maxtime"]=ini_get('max_execution_time');
        $server["allow_url_fopen"]= (ini_get('allow_url_fopen') ? '允许' : '不允许');
        $server["safe_mode"]  = (ini_get('safe_mode') ? '是' : '否');
        $server["register_globals"]=(ini_get('register_globals')?'打开':'关闭');
        $server["upload_max_filesize"]=ini_get('upload_max_filesize');
        $server["SERVER_PORT"]=$_SERVER["SERVER_PORT"];
        $server["filename"]=__FILE__;
        return $server;
    }
}
?>
